package br.ufla.pgcc.oomeasures.measures;

import br.ufla.pgcc.oomeasures.astvisitors.AttributeVisitor;
import br.ufla.pgcc.oomeasures.astvisitors.ClassVisitor;

/**
 * Classe que implementa a medida da suite MOOD Attribute Hiding Factor, que mede as invisibilidades de atributos 
 * nas aulas. A invisibilidade de um atributo eh a percentagem das classes totais a partir 
 * da qual o atributo nao eh visivel.
 * 
 * @author Ramon Abilio
 *
 */
public class AttributeHidingFactor extends Measure{

	private double value;
	
	public AttributeHidingFactor(){
		super();
		value=0d;
		addApplicableGranularity(Granularity.CLASS);
	}
	
	@Override
	public String getName() {
		return "Attribute Hiding Factor";
	}

	@Override
	public String getAcronym() {
		return "AHF";
	}

	@Override
	public String getDescription() {
		return "Measures how variables are encapsulated in a class";
	}

	@Override
	public double getMinValue() {
		return 0;
	}

	@Override
	public double getMaxValue() {
		return 1;
	}

	@Override
	public double getRefValue() {
		return 1;
	}

	@Override
	public double getCalculatedValue() {
		return value;
	}

	@Override
	public void setCalculatedValue(double value) {
		this.value = value;
	}

	@Override
	public <T> void measure(T unit) {
		
		double numOfPrivateAttributes = AttributeVisitor.getNumberOfProjectPrivateAttributes();
		double numOfClasses           = ClassVisitor.getNumOfProjectClasses();
		double numOfMethods           = AttributeVisitor.getNumberOfProjectAttributes();
		
		double mhf = 100 - ((numOfPrivateAttributes/(numOfClasses-1)/numOfMethods)*100);
		setCalculatedValue(mhf);
	}

}
